#include <iostream>
#include <stack>
#include <string>

bool isValidBracketSequence(const std::string& sequence) {
    std::stack<char> brackets;

    for (char bracket : sequence) {
        if (bracket == '('  bracket == '['  bracket == '{' || bracket == '<') {
            brackets.push(bracket);
        } else if (bracket == ')') {
            if (brackets.empty() || brackets.top() != '(') {
                return false;
            } else {
                brackets.pop();
            }
        } else if (bracket == ']') {
            if (brackets.empty() || brackets.top() != '[') {
                return false;
            } else {
                brackets.pop();
            }
        } else if (bracket == '}') {
            if (brackets.empty() || brackets.top() != '{') {
                return false;
            } else {
                brackets.pop();
            }
        } else if (bracket == '>') {
            if (brackets.empty() || brackets.top() != '<') {
                return false;
            } else {
                brackets.pop();
            }
        }
    }

    return brackets.empty();
}

int main() {
    std::string sequence;
    std::cout << "Enter a bracket sequence: ";
    std::cin >> sequence;

    if (isValidBracketSequence(sequence)) {
        std::cout << "True\n";
    } else {
        std::cout << "False\n";
    }

    return 0;
}
